package olcnt

import (
	"time"
	"wanyu/server/engine/globaldef/consts"
	"wanyu/server/engine/logger"
	"wanyu/server/engine/wpcfg"
)

//PostInterval 写日志的间隔
const PostInterval = time.Duration(5)*time.Minute

var l *logger.Logger

/**配置文件
{
    "logger" : {
        "olcnt" : {
            "addrs" : [
                "192.168.0.193:9092"
            ],
            "partition":0,
            "maxBytes":0,
            "MaxMsgCnt":0
        }
    }
}*/
//初始化
func Init() {
	var c logger.Config
	wpcfg.ScanNode(consts.ConfigServer, &c, "logger", "olcnt")
	l = logger.NewLogger("olcnt", &c)
	if l == nil {
		panic("create olcnt logger failed")
	}
}

//OnlineCountLog 代理的在线玩家数
type OnlineCountLog struct {
	Data map[string]uint32 `json:"data"` //数据
	Time int64             `json:"time"` //统计时间
}

//Post 提交日志
func Post(data map[string]uint32, now time.Time) {
	l.Log(map[string]interface{}{
		"data": data,
		"time": now.Unix(),
	})
}
